<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    <title>How much is my currency? - Zend Framework Manual</title>

    <link href="../css/shCore.css" rel="stylesheet" type="text/css" />
    <link href="../css/shThemeDefault.css" rel="stylesheet" type="text/css" />
    <link href="../css/styles.css" media="all" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>Zend Framework</h1>
<h2>Programmer's Reference Guide</h2>
<ul>
    <li><a href="../en/zend.currency.value.html">Inglês (English)</a></li>
    <li><a href="../pt-br/zend.currency.value.html">Português Brasileiro (Brazilian Portuguese)</a></li>
</ul>
<table width="100%">
    <tr valign="top">
        <td width="85%">
            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="zend.currency.number.html">How does the currency look like?</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="zend.currency.html">Zend_Currency</a></span><br />
                        <span class="home"><a href="manual.html">Programmer's Reference Guide</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="zend.currency.calculation.html">Calculating with currencies</a></div>
                    </td>
                </tr>
            </table>
<hr />
<div id="zend.currency.value" class="section"><div class="info"><h1 class="title">How much is my currency?</h1></div>
    

    <p class="para">
        When you are working with currencies then you normally want to display an amount of
        money. And when you work with different currencies then you have to do this with three
        different things. The amount you want to display, the precision you want to use, and
        probably the exchange rate.
    </p>

    <div class="section" id="zend.currency.value.money"><div class="info"><h1 class="title">Working with currency values</h1></div>
        

        <p class="para">
            The currency value, a.k.a. the money, you want to use can easily be set by using the
            <span class="property">value</span> option.
        </p>

        <pre class="programlisting brush: php">
$currency = new Zend_Currency(
    array(
        &#039;value&#039;    =&gt; 1000,
        &#039;currency&#039; =&gt; &#039;USD&#039;,
    )
);

print $currency; // Could return &#039;$ 1.000&#039;
</pre>


        <p class="para">
            Using the  <span class="methodname">setFormat()</span> method with this array option, and
            also by using the  <span class="methodname">setValue()</span> method you can set the value
            afterwards.
        </p>

        <pre class="programlisting brush: php">
$currency = new Zend_Currency(
    array(
        &#039;value&#039;    =&gt; 1000,
        &#039;currency&#039; =&gt; &#039;USD&#039;,
    )
);

print $currency-&gt;setValue(2000); // Could return &#039;$ 2.000&#039;
</pre>


        <p class="para">
            With the  <span class="methodname">getValue()</span> method you will get the actual set
            value.
        </p>
    </div>

    <div class="section" id="zend.currency.value.precision"><div class="info"><h1 class="title">Using precision on currencies</h1></div>
        

        <p class="para">
            When working with currencies they you probably also have to handle precision.
            Most currencies use a precision of 2. This means that when you have 100 US dollars
            you could also have 50 cents. The related value is simply a floating value.
        </p>

        <pre class="programlisting brush: php">
$currency = new Zend_Currency(
    array(
        &#039;value&#039;    =&gt; 1000.50,
        &#039;currency&#039; =&gt; &#039;USD&#039;,
    )
);

print $currency; // Could return &#039;$ 1.000,50&#039;
</pre>


        <p class="para">
            Of course, as the default precision is 2, you will get &#039;00&#039; for the decimal value
            when there is no precision to display.
        </p>

        <pre class="programlisting brush: php">
$currency = new Zend_Currency(
    array(
        &#039;value&#039;    =&gt; 1000,
        &#039;currency&#039; =&gt; &#039;USD&#039;,
    )
);

print $currency; // Could return &#039;$ 1.000,00&#039;
</pre>


        <p class="para">
            To get rid of this default precision you could simply use the
            <span class="property">precision</span> option and set it to &#039;0&#039;. And you can set any other
            precision you want to use between 0 and 9. All values will be rounded or streched
            when they don&#039;t fit the set precision.
        </p>

        <pre class="programlisting brush: php">
$currency = new Zend_Currency(
    array(
        &#039;value&#039;     =&gt; 1000,30,
        &#039;currency&#039;  =&gt; &#039;USD&#039;,
        &#039;precision&#039; =&gt; 0
    )
);

print $currency; // Could return &#039;$ 1.000&#039;
</pre>

    </div>
</div>
        <hr />

            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="zend.currency.number.html">How does the currency look like?</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="zend.currency.html">Zend_Currency</a></span><br />
                        <span class="home"><a href="manual.html">Programmer's Reference Guide</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="zend.currency.calculation.html">Calculating with currencies</a></div>
                    </td>
                </tr>
            </table>
</td>
        <td style="font-size: smaller;" width="15%"> <style type="text/css">
#leftbar {
	float: left;
	width: 186px;
	padding: 5px;
	font-size: smaller;
}
ul.toc {
	margin: 0px 5px 5px 5px;
	padding: 0px;
}
ul.toc li {
	font-size: 85%;
	margin: 1px 0 1px 1px;
	padding: 1px 0 1px 11px;
	list-style-type: none;
	background-repeat: no-repeat;
	background-position: center left;
}
ul.toc li.header {
	font-size: 115%;
	padding: 5px 0px 5px 11px;
	border-bottom: 1px solid #cccccc;
	margin-bottom: 5px;
}
ul.toc li.active {
	font-weight: bold;
}
ul.toc li a {
	text-decoration: none;
}
ul.toc li a:hover {
	text-decoration: underline;
}
</style>
 <ul class="toc">
  <li class="header home"><a href="manual.html">Programmer's Reference Guide</a></li>
  <li class="header up"><a href="manual.html">Programmer's Reference Guide</a></li>
  <li class="header up"><a href="reference.html">Zend Framework Reference</a></li>
  <li class="header up"><a href="zend.currency.html">Zend_Currency</a></li>
  <li><a href="zend.currency.introduction.html">Introduction to Zend_Currency</a></li>
  <li><a href="zend.currency.usage.html">Using Zend_Currency</a></li>
  <li><a href="zend.currency.options.html">Options for currencies</a></li>
  <li><a href="zend.currency.description.html">What makes a currency?</a></li>
  <li><a href="zend.currency.position.html">Where is the currency?</a></li>
  <li><a href="zend.currency.number.html">How does the currency look like?</a></li>
  <li class="active"><a href="zend.currency.value.html">How much is my currency?</a></li>
  <li><a href="zend.currency.calculation.html">Calculating with currencies</a></li>
  <li><a href="zend.currency.exchange.html">Exchanging currencies</a></li>
  <li><a href="zend.currency.additional.html">Additional informations on Zend_Currency</a></li>
 </ul>
 </td>
    </tr>
</table>

<script type="text/javascript" src="../js/shCore.js"></script>
<script type="text/javascript" src="../js/shAutoloader.js"></script>
<script type="text/javascript" src="../js/main.js"></script>

</body>
</html>